package com.shop;

import com.alibaba.fastjson.JSONObject;
import com.shop.user.po.User;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashMap;

/**
 * @author 'banxia'
 * @version 1.0
 * @description TODO
 * @date 2023/2/22 0:34
 */
@SpringBootTest(classes = Application.class)
public class test {

    @Test
    public void test(){
        User user=new User();
        user.setAccount("#1231");
        user.setName("dassd");
        //例如 json为  {"account":"#1231","name":"dassd"}
        String s = JSONObject.toJSONString(user);
        //获取s中包含的所有json字段
        String t = s.substring(1, s.length() - 1);//去掉{}
        String[] split = t.split(",");//分成多个字段
        HashMap<String,String> map=new HashMap<>();
        for (String st : split) {
            String[] sp = st.split(":");
            String key=sp[0].substring(1,sp[0].length()-1); //属性名称
            String val=sp[1].substring(1,sp[1].length()-1); //属性值
            map.put(key,val);
        }
        

    }

}
